package com.teama4.shop.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

public class FileUtil {
    public static boolean dictionary_add(MultipartFile multipartFile , String filepath,String filename) {


        try { FtpUtils ftp =new FtpUtils();
            File file = File.createTempFile("tmp", null);
            multipartFile.transferTo(file);
            InputStream inputStream = new FileInputStream(file);
            ftp.uploadFile(filepath, filename, inputStream);
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }



    }
    public static String delFile(String filepathAndName) {
        File file = new File(filepathAndName);
        // 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
        if (file.exists() && file.isFile()) {
            if (file.delete()) {
                return "ok";
            } else {
                return "fail";
            }
        } else {
            return "unExit";
        }

    }

}
